package com.ruoyi.jksd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.jksd.common.dto.XyDepositDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jksd.domain.XyDeposit;
import com.ruoyi.jksd.service.IXyDepositService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员-余额提现Controller
 *
 * @author ruoyi
 * @date 2024-05-26
 */
@RestController
@RequestMapping("/xydeposit/xydeposit")
public class XyDepositController extends BaseController {
    @Autowired
    private IXyDepositService xyDepositService;

    /**
     * 查询会员-余额提现列表
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:list')")
    @GetMapping("/list")
    public TableDataInfo list(XyDeposit xyDeposit) {
        startPage();
        List<XyDeposit> list = xyDepositService.selectXyDepositList(xyDeposit);
        return getDataTable(list);
    }

    /**
     * 导出会员-余额提现列表
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:export')")
    @Log(title = "会员-余额提现", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XyDeposit xyDeposit) {
        List<XyDeposit> list = xyDepositService.selectXyDepositList(xyDeposit);
        ExcelUtil<XyDeposit> util = new ExcelUtil<XyDeposit>(XyDeposit.class);
        util.exportExcel(response, list, "会员-余额提现数据");
    }

    /**
     * 获取会员-余额提现详细信息
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(xyDepositService.selectXyDepositById(id));
    }

    /**
     * 新增会员-余额提现
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:add')")
    @Log(title = "会员-余额提现", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XyDeposit xyDeposit) {
        return success(xyDepositService.insertXyDeposit(xyDeposit));
    }

    /**
     * 申请余额提现
     */
    @Log(title = "会员-余额提现", businessType = BusinessType.INSERT)
    @PostMapping("applyWithDraw")
    public AjaxResult applyWithDraw(@RequestBody XyDepositDto xyDeposit) {
        return xyDepositService.withdraw(xyDeposit);
    }


    /**
     * 审批提现
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:add')")
    @Log(title = "审批余额提现", businessType = BusinessType.INSERT)
    @PostMapping("/approvalWithDraw")
    public AjaxResult approvalWithDraw(@RequestBody XyDeposit xyDeposit) {
        return xyDepositService.approvalWithDraw(xyDeposit);
    }

    /**
     * 修改会员-余额提现
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:edit')")
    @Log(title = "会员-余额提现", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XyDeposit xyDeposit) {
        return toAjax(xyDepositService.updateXyDeposit(xyDeposit));
    }

    /**
     * 删除会员-余额提现
     */
    @PreAuthorize("@ss.hasPermi('xydeposit:xydeposit:remove')")
    @Log(title = "会员-余额提现", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(xyDepositService.deleteXyDepositByIds(ids));
    }
}
